package com.example.tao_city.text1;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by TAO_CITY on 2018/1/19.
 */

public class Fm1_Chaxun1 extends Activity implements View.OnClickListener{
    private ImageView back;
    private TextView bangka,tieka,dukaqi;
    private ImageView lin1,lin2,lin3,baiyu;
    private RelativeLayout bangkaview,tiekaview,dukaqiview;
    private ImageView singer1,singer2,singer3;
    private boolean stop=true;
    private boolean dukar=true;
    private boolean jindu=true;
    private int tiekanumber=0,dukanumber=0;
    private Handler handler;
    private ImageView jindu01,jindu02,jindu03,jindu04,jindu05,jindu06,jindu07,jindu08,jindu09;
    private RelativeLayout heimu;
    private EditText kahao;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fm1_chaxun1);
        handler=new Handler();
        initview();
    }

    @Override
    protected void onPause() {
        super.onPause();
        stop=false;
        dukar=false;
    }

    private void initview() {
        back=findViewById(R.id.fm1_chaxun_back1);
        bangka=findViewById(R.id.fm1_chaxun_bangka1);
        tieka=findViewById(R.id.fm1_chaxun_tieka1);
        dukaqi=findViewById(R.id.fm1_chaxun_dukaqi1);
        lin1=findViewById(R.id.chaxun_bangkaline1);
        lin2=findViewById(R.id.chaxun_tiekaline1);
        lin3=findViewById(R.id.chaxun_dukaqiline1);
        bangkaview=findViewById(R.id.chaxun_bangkaview);
        tiekaview=findViewById(R.id.chaxun_tiekaview);
        dukaqiview=findViewById(R.id.chaxun_dukaqiview);
        singer1=findViewById(R.id.tieka1_singel1);
        singer2=findViewById(R.id.tieka1_singel2);
        singer3=findViewById(R.id.tieka1_singel3);
        jindu01=findViewById(R.id.dukaqi_jindu01);
        jindu02=findViewById(R.id.dukaqi_jindu02);
        jindu03=findViewById(R.id.dukaqi_jindu03);
        jindu04=findViewById(R.id.dukaqi_jindu04);
        jindu05=findViewById(R.id.dukaqi_jindu05);
        jindu06=findViewById(R.id.dukaqi_jindu06);
        jindu07=findViewById(R.id.dukaqi_jindu07);
        jindu08=findViewById(R.id.dukaqi_jindu08);
        jindu09=findViewById(R.id.dukaqi_jindu09);
        heimu=findViewById(R.id.chaxun1_hei1);
        baiyu=findViewById(R.id.dukaqi_baiyun1);
        kahao=findViewById(R.id.bangka_kahao1);
        button=findViewById(R.id.bangka_button1);

        button.setOnClickListener(this);
        baiyu.setOnClickListener(this);
        bangka.setOnClickListener(this);
        tieka.setOnClickListener(this);
        dukaqi.setOnClickListener(this);
        back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.fm1_chaxun_back1:
                finish();
                break;
            case R.id.fm1_chaxun_bangka1:
                selectview(1);
                break;
            case R.id.fm1_chaxun_tieka1:
                selectview(2);
                break;
            case R.id.fm1_chaxun_dukaqi1:
                selectview(3);
                break;
            case R.id.dukaqi_baiyun1:
                if(jindu) {
                    heimu.setVisibility(View.VISIBLE);
                    tieka.setEnabled(false);
                    dukaqi.setEnabled(false);
                    bangka.setEnabled(false);
                    back.setEnabled(false);
                    dukar = true;
                    dukaqirun.run();
                    jindu=false;
                }else {
                    setbianan();
                    heimu.setVisibility(View.INVISIBLE);
                    tieka.setEnabled(true);
                    dukaqi.setEnabled(true);
                    bangka.setEnabled(true);
                    back.setEnabled(true);
                    dukanumber = 0;
                    dukar = false;
                    jindu=true;
                }
                break;
            case R.id.bangka_button1:
                String kh= String.valueOf(kahao.getText());
                if(kh.equals("12306")){
                    Intent int1=new Intent();
                    int1.setClass(this,Chaxun_Record.class);
                    startActivity(int1);
                }else {
                    Toast.makeText(this,"错误",Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
    private void  selectview(int i){
        switch (i){
            case 1:
                setcolor();
                setsingerview();
                bangka.setTextColor(Color.parseColor("#458fee"));
                lin1.setVisibility(View.VISIBLE);
                bangkaview.setVisibility(View.VISIBLE);
                stop=false;
                break;
            case 2:
                setcolor();
                tieka.setTextColor(Color.parseColor("#458fee"));
                lin2.setVisibility(View.VISIBLE);
                tiekaview.setVisibility(View.VISIBLE);
                tiekanumber=0;
                stop=true;
                tiekarun.run();
                break;
            case 3:
                setcolor();
                setsingerview();
                dukaqi.setTextColor(Color.parseColor("#458fee"));
                lin3.setVisibility(View.VISIBLE);
                dukaqiview.setVisibility(View.VISIBLE);
                stop=false;
                break;
        }
    }
    private void setcolor() {
        bangka.setTextColor(Color.parseColor("#808080"));
        tieka.setTextColor(Color.parseColor("#808080"));
        dukaqi.setTextColor(Color.parseColor("#808080"));
        lin1.setVisibility(View.INVISIBLE);
        lin2.setVisibility(View.INVISIBLE);
        lin3.setVisibility(View.INVISIBLE);
        bangkaview.setVisibility(View.INVISIBLE);
        tiekaview.setVisibility(View.INVISIBLE);
        dukaqiview.setVisibility(View.INVISIBLE);
    }
    Runnable tiekarun=new Runnable() {
        @Override
        public void run() {
            if(stop){
                    setsingerview();
                    switch (tiekanumber){
                        case 1:
                            singer1.setVisibility(View.VISIBLE);
                            break;
                        case 2:
                            singer2.setVisibility(View.VISIBLE);
                            break;
                        case 3:
                            singer3.setVisibility(View.VISIBLE);
                            break;
                    }
                    tiekanumber++;
                    if(tiekanumber==4) {
                        tiekanumber = 0;
                    }
                handler.postDelayed(this,500);
                Log.e("1111","1111");
            }

        }
    };

    Runnable dukaqirun=new Runnable() {
        @Override
        public void run() {
            if(dukar){
                setbianan();
                setliang(dukanumber);
                dukanumber++;
                if(dukanumber==10){
                    dukanumber=0;
                }
                handler.postDelayed(this,500);
                Log.e("2222","2222");
            }

        }
    };
    private void setsingerview(){
        singer1.setVisibility(View.INVISIBLE);
        singer2.setVisibility(View.INVISIBLE);
        singer3.setVisibility(View.INVISIBLE);
    }
    private void setbianan(){
        jindu01.setVisibility(View.INVISIBLE);
        jindu02.setVisibility(View.INVISIBLE);
        jindu03.setVisibility(View.INVISIBLE);
        jindu04.setVisibility(View.INVISIBLE);
        jindu05.setVisibility(View.INVISIBLE);
        jindu06.setVisibility(View.INVISIBLE);
        jindu07.setVisibility(View.INVISIBLE);
        jindu08.setVisibility(View.INVISIBLE);
        jindu09.setVisibility(View.INVISIBLE);
    }
    private void setliang(int i){
        switch (i){
            case 1:
                jindu01.setVisibility(View.VISIBLE);
                break;
            case 2:
                jindu01.setVisibility(View.VISIBLE);
                jindu02.setVisibility(View.VISIBLE);
                break;
            case 3:
                jindu01.setVisibility(View.VISIBLE);
                jindu02.setVisibility(View.VISIBLE);
                jindu03.setVisibility(View.VISIBLE);
                break;
            case 4:
                jindu01.setVisibility(View.VISIBLE);
                jindu02.setVisibility(View.VISIBLE);
                jindu03.setVisibility(View.VISIBLE);
                jindu04.setVisibility(View.VISIBLE);
                break;
            case 5:
                jindu01.setVisibility(View.VISIBLE);
                jindu02.setVisibility(View.VISIBLE);
                jindu03.setVisibility(View.VISIBLE);
                jindu04.setVisibility(View.VISIBLE);
                jindu05.setVisibility(View.VISIBLE);
                break;
            case 6:
                jindu01.setVisibility(View.VISIBLE);
                jindu02.setVisibility(View.VISIBLE);
                jindu03.setVisibility(View.VISIBLE);
                jindu04.setVisibility(View.VISIBLE);
                jindu05.setVisibility(View.VISIBLE);
                jindu06.setVisibility(View.VISIBLE);
                break;
            case 7:
                jindu01.setVisibility(View.VISIBLE);
                jindu02.setVisibility(View.VISIBLE);
                jindu03.setVisibility(View.VISIBLE);
                jindu04.setVisibility(View.VISIBLE);
                jindu05.setVisibility(View.VISIBLE);
                jindu06.setVisibility(View.VISIBLE);
                jindu07.setVisibility(View.VISIBLE);
                break;
            case 8:
                jindu01.setVisibility(View.VISIBLE);
                jindu02.setVisibility(View.VISIBLE);
                jindu03.setVisibility(View.VISIBLE);
                jindu04.setVisibility(View.VISIBLE);
                jindu05.setVisibility(View.VISIBLE);
                jindu06.setVisibility(View.VISIBLE);
                jindu07.setVisibility(View.VISIBLE);
                jindu08.setVisibility(View.VISIBLE);
                break;
            case 9:
                jindu01.setVisibility(View.VISIBLE);
                jindu02.setVisibility(View.VISIBLE);
                jindu03.setVisibility(View.VISIBLE);
                jindu04.setVisibility(View.VISIBLE);
                jindu05.setVisibility(View.VISIBLE);
                jindu06.setVisibility(View.VISIBLE);
                jindu07.setVisibility(View.VISIBLE);
                jindu08.setVisibility(View.VISIBLE);
                jindu09.setVisibility(View.VISIBLE);
                break;
        }
    }
}
